<template>
  <view>
    <!-- <anilSeat :title="movieInfo.filmName" :info="timeData+'|'+movieInfo.versionType" :room-name="officeInfo.hallName"
			:max="max" :seatData="dataList" @confirm="getInfo">
		</anilSeat> -->
    <anilSeat
      :title="movieInfo.filmName"
      :info="timeData"
      :room-name="officeInfo.hallName"
      :max="max"
      :seatData="dataList"
      @confirm="getInfo"
    >
    </anilSeat>
  </view>
</template>

<script>
import anilSeat from "./components/anil-seat.vue";
// import {getSeat,createOrder} from "@/api/film.js"
// import config from '../../utils/config.js';
import sheep from "@/sheep";
// import dataArr from '../../utils/dataArray.js';
export default {
  components: {
    anilSeat,
  },
  data() {
    return {
      dataList: [],
      max: 4,
      cinemaId: "",
      movieInfo: {},
      officeInfo: {},
      timeData: "",
      seats: [],
    };
  },
  onLoad(opt) {
    let _this = this;
    const eventChannel = this.getOpenerEventChannel();

    // eventChannel.on('moviceDataFrom', function(data) {
    // 	console.log(data)
    // })
    _this.movieInfo = JSON.parse(decodeURIComponent(opt.chooseMovice));
    let item = JSON.parse(decodeURIComponent(opt.item));
    // _this.timeData = config.turnTime(item.stopSellTime, 0)
    this.officeInfo = item;
    console.log("seat", opt);
    this.cinemaId = opt.cinemaId;

    _this.timeData = this.getTime(item.showTime);
    console.log("_this.officeInfo", this.officeInfo);
    this.getData();
    // this.cinemaInfo = JSON.parse(decodeURIComponent(opt.cinemaInfo));
  },
  methods: {
    goBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    getTime(timestamp) {
      // 创建一个Date对象
      const date = new Date(timestamp);
      // 获取小时和分钟
      const hours = date.getHours().toString().padStart(2, "0"); // 使用padStart确保是两位数
      const minutes = date.getMinutes().toString().padStart(2, "0"); // 使用padStart确保是两位数
      // 返回格式化后的字符串
      return `${hours}:${minutes}`;
    },
    async getData() {
      const res = await sheep.$api.movie.seatList({
        showId: this.officeInfo.id,
      });
      if (res.code == 200) {
        this.seats = res.data.seats;
        const dataArr = res.data.seats.map((item) => {
          item.columnNo = item.col;
          item.rowNo = item.row;
          item.seatId = item.seatNo;
          item.pai = item.row;
          item.lie = item.col;
          const matchedRegion = res.data.regions.find(
            (e) => e.regionName === item.regionName
          );
          item.price = matchedRegion ? matchedRegion.price : 0; // 未找到时设置默认值
          item.status = item.canUse ? "N" : "Y";
          return item;
        });

        let arrat = [];
        dataArr.forEach((item) => {
          // let pai = item.seatNo.split('��');
          // let lie = pai[1].split('��')
          arrat.push({
            YCoord: item.rowNo,
            XCoord: item.columnNo,
            SeatCode: item.seatId,
            Status: item.status == "N" ? 0 : 1,
            Price: item.price,
            RowNum: item.pai,
            ColumnNum: item.lie,
            // seatName:item.seatNo
          });
        });
        setTimeout(() => {
          this.dataList = arrat;
          this.$forceUpdate();
        }, 500);
      }
      // const dataArr = [{
      // 	areaId: "",
      // 	columnNo: "1",
      // 	lie: "11",
      // 	loveStatus: 0,
      // 	pai: "1",
      // 	rowNo: "1",
      // 	seatId: "MjUyNDlAX0AxNDY2MjlAX0AxNjUyNTI4NDAwQF9AMTA5QF9ANDlAX0Ax5o6SMTHluqdAX0A0OUBfQDBAX0Ax5o6SMTHluqdAX0AzMDA1NA==",
      // 	seatNo: "1排11座",
      // 	status: "N",
      // }, {
      // 	areaId: "",
      // 	columnNo: "2",
      // 	lie: "10",
      // 	loveStatus: 0,
      // 	pai: "1",
      // 	rowNo: "1",
      // 	seatId: "MjUyNDlAX0AxNDY2MjlAX0AxNjUyNTI4NDAwQF9AMTA5QF9ANDlAX0Ax5o6SMTDluqdAX0A0OUBfQDBAX0Ax5o6SMTDluqdAX0AzMDA1NA==",
      // 	seatNo: "1排10座",
      // 	status: "N",
      // }, {
      // 	areaId: "",
      // 	columnNo: "3",
      // 	lie: "9",
      // 	loveStatus: 0,
      // 	pai: "1",
      // 	rowNo: "1",
      // 	seatId: "MjUyNDlAX0AxNDY2MjlAX0AxNjUyNTI4NDAwQF9AMTA5QF9ANDlAX0Ax5o6SOeW6p0BfQDQ5QF9AMEBfQDHmjpI55bqnQF9AMzAwNTQ=",
      // 	seatNo: "1排9座",
      // 	status: "N",
      // }]
      // console.log(dataArr)
      // console.log(this.dataList)
    },

    getInfo(e) {
      let array = [];
      let price = 0;
      e.forEach((item) => {
        console.log("currentSelectSeat", item);
        price += item.Price;
        const findIndex = this.seats.findIndex(
          (seat) => seat.seatNo === item.SeatCode
        );
        const params = {
          row: this.seats[findIndex].row,
          col: this.seats[findIndex].col,
          seatName: this.seats[findIndex].seatNo,
          price: this.seats[findIndex].price,
        };
        array.push(params);
      });
      let prm = {
        officeInfo: this.officeInfo,
        cinemaId: this.cinemaId,
        movieInfo: this.movieInfo,
        showInfor: array,
        price: price,
      };
      uni.navigateTo({
        url: `/pages/movie/confirm-order?prm=${encodeURIComponent(
          JSON.stringify(prm)
        )}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
